package cn.tedu._05weibo.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.print.attribute.standard.JobSheets;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;

    public JsonResult(StatuCode statuCode) {
        this.state=statuCode.getState();
        this.message=statuCode.getMessage();
    }

    public JsonResult(StatuCode statuCode ,Object data) {
        this.state=statuCode.getState();
        this.message=statuCode.getMessage();
        this.data = data;
    }
    /*
    以下两个静态方法都是针对操作成功的场景，比如：登录成功，注册成功，发微博成功.....
    1.针对有具体数据的返回方法
    2.没有具体数据的方法
     */
    public static JsonResult ok(Object data){
        return new JsonResult(StatuCode.OPERTION_SUCCESS,data);
    }
    public static JsonResult ok(){
        return ok(null);
    }

    public static JsonResult fail(Object data){
        return new JsonResult(StatuCode.OPERTION_FAILED,data);
    }
}
